<?php
/**
 * CustomJWTProvider.php
 *
 * Author: Guo
 * Email jonasyeah@163.com
 *
 * Date:   2019-08-19 21:00
 */

namespace App\Commons\Libs\JWTAuth;

// use App\Commons\Domain\Module\Account\Entity\TokenEntity;
use Illuminate\Support\Carbon;
use Lcobucci\JWT\Builder;
use Lcobucci\JWT\Parser;
use Tymon\JWTAuth\Providers\JWT\Lcobucci;

class CustomJWTProvider extends Lcobucci
{
    public function __construct(
        Builder $builder,
        Parser $parser,
        $secret,
        $algo,
        array $keys
    ) {
        parent::__construct($builder, $parser, $secret, $algo, $keys);
    }

    public function encode(array $payload)
    {
        $token = parent::encode($payload);

        // $created_at = Carbon::Parse(date('Y-m-d H:i:s', $payload['iat']));
        // $expire_in = $created_at->addMinutes(config('jwt.refresh_ttl', 20160));
        // // 保存token到数据库
        // app(TokenEntity::class)->create(
        //     $payload['sub'],
        //     $token,
        //     $expire_in->toDateTimeString(),
        //     config('app.name', 'default')
        // );
        return $token;
    }
}
